<?php
if(!defined('IN_CRONLITE'))exit();
class Template {

	static public function getList(){
		$dir = TEMPLATE_ROOT;
		$dirArray[] = NULL;
        if (false != ($handle = opendir($dir))) {
            $i = 0;
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != ".." && !strpos($file, ".")) {
                    $dirArray[$i] = $file;
                    $i++;
                }
            }
            closedir($handle);
        }
        return $dirArray;
	}

	static public function load($type, $name = 'index'){
		global $conf;
		if($type == 'Index'){
    		$template = $conf['template']?$conf['template']:'default';
    		if(!preg_match('/^[a-zA-Z0-9]+$/',$name)) exit('error');
    		$filename = TEMPLATE_ROOT.$template.'/'.$name.'.php';
    		$filename_default = TEMPLATE_ROOT.'default/'.$name.'.php';
    		if(file_exists($filename)){
    			return $filename;
    		}elseif(file_exists($filename_default)){
    			return $filename_default;
    		}else{
    			sysmsg('<h3>找不到模板文件！</h3>');
    		}
    	}else{
    		exit('no！');
    	}
	}

	static public function exists($template){
		$filename = TEMPLATE_ROOT.$template.'/index.php';
		if(file_exists($filename)){
			return true;
		}else{
			return false;
		}
	}
}

